_id']; $gdpr_checked = $field['enabled']; $text = $field['text']; // Add to the checkbox output $checkbox .= ""; $checkbox .= ""; $checkbox .= "
"; } $checkbox .= "

"; $checkbox .= ""; } if (is_checkout() && $hide_optin_for_subscriber) { $checkbox = ''; } echo apply_filters( 'mailchimp_woocommerce_newsletter_field', $checkbox, $status, $label); } } /** * @param $order_id * @param $posted */ public function processNewsletterField($order_id, $posted) { $this->handleStatus($order_id); } /** * @param $order */ public function processPayPalNewsletterField($order) { $this->handleStatus($order->get_id()); } /** * @param $sanitized_user_login * @param $user_email * @param $reg_errors */ public function processRegistrationForm($sanitized_user_login, $user_email, $reg_errors) { if (defined('WOOCOMMERCE_CHECKOUT')) { return; // Ship checkout } $this->handleStatus(); } /** * @param null $order_id * @return bool|int */ protected function handleStatus($order_id = null) { $post_key = 'mailchimp_woocommerce_newsletter'; $meta_key = 'mailchimp_woocommerce_is_subscribed'; $logged_in = is_user_logged_in(); // if the post key is available we use it - otherwise we null it out. $status = isset($_POST[$post_key]) ? (int) $_POST[$post_key] : null; // if the status is null, we don't do anything if ($status === null) { return false; } // if we passed in an order id, we update it here. if ($order_id) { MailChimp_WooCommerce_HPOS::update_order_meta($order_id, $meta_key, $status); //update_post_meta($order_id, $meta_key, $status); } // if the user is logged in, we will update the status correctly. if ($logged_in) { update_user_meta(get_current_user_id(), $meta_key, $status); return $status; } return false; } }